
import csv

def read_data_from_csv(filepath):

    # 读取csv文件中数据
    with open(filepath, 'r') as f:
        datas = csv.reader(f)
        # # 如果有标题行跳过
        # next(datas, None)
        # 定义一个空列表，用于存放数据
        lis = []
        # 使用一个for循环把文件中的datas中的数据读取存入lis中
        for item in datas:
            lis.append(item)

        # 删除标题行
        lis.pop(0)
        print('数据', lis)
        return lis

# read_data_from_csv('login.csv')



from openpyxl import load_workbook

# 方法1：读取Excel文件数据
class read_data_from_excel():

    def __init__(self, path, sheetname):
        self.path = load_workbook(path)
        self.sheetname = self.path[sheetname]

    def getdata(self):
        datalist = []
        for item in self.sheetname:
            list = []
            list.append(item[0].value)
            list.append(item[1].value)
            list.append(item[2].value)
            list.append(item[3].value)
            datalist.append(list)

        datalist.pop(0)
        return datalist


# path = r'E:\zhuangaoer_pyCharm\zhuangaowuday1\login.xlsx'
# sheetname = 'Sheet1'
# dy = read_data_from_excel(path, sheetname)
# print(dy.getdata())


# 方法2：读取Excel文件数据

import pandas

def get_excel(filepath):
    df = pandas.read_excel(filepath)
    test_data = []
    for index, row in df.iterrows():
        test_data.append([row['username'], row['password'], row['casename'], row['expected']])

    return test_data

# 获取Excel数据
# print(get_excel(r'./login.xlsx'))


